package com.po;

import java.io.Serializable;
import java.util.List;

public class Page<T>  implements Serializable{

    private T t;
    private List<T> list;
    private Integer currentPage=1;
    private Integer totalPage;
    private Integer totalCount;
    private Integer pageSize=10;

    private Integer startIndex = 0;
    private Integer endIndex=10;

    public T getT() {
        return t;
    }

    public void setT(T t) {
        this.t = t;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public Integer getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(Integer currentPage) {
        if(pageSize !=  null && currentPage != null){
            startIndex = (currentPage-1)*pageSize;
            endIndex = startIndex+pageSize;
        }
        this.currentPage = currentPage;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        if(pageSize !=  null && totalCount != null){
            int p = totalCount/pageSize;
            totalPage = p*pageSize<totalCount?p+1:p;
            startIndex = (currentPage-1)*pageSize;
            endIndex = startIndex+pageSize;
        }
        this.totalCount = totalCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        if(pageSize !=  null && currentPage != null){
            startIndex = (currentPage-1)*pageSize;
            endIndex = startIndex+pageSize;
        }
        this.pageSize = pageSize;
    }

    public Integer getStartIndex() {
        return startIndex;
    }

    public void setStartIndex(Integer startIndex) {
        this.startIndex = startIndex;
    }

    public Integer getEndIndex() {
        return endIndex;
    }

    public void setEndIndex(Integer endIndex) {
        this.endIndex = endIndex;
    }
}
